﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace mbine.msgc.model
{
    public sealed class CLog
    {
        public string LogPath { get; set; }
        static CLog instance = null;
        static readonly object padlock = new object();

        CLog()
        {
        }

        public static CLog Instance
        {
            get
            {
                lock (padlock)
                {
                    if (instance == null)
                    {
                        instance = new CLog();
                    }
                    return instance;
                }
            }
        }

        public void WLog(string _s)
        {
            if (!System.IO.Directory.Exists(this.LogPath))
                System.IO.Directory.CreateDirectory(this.LogPath);

            System.IO.File.AppendAllText(this.LogPath + "\\log_" + DateTime.Now.ToShortDateString() + "_W"
                , DateTime.Now.ToLongTimeString() + " : " + _s + "\n");
        }

        public void ELog(string _s)
        {
            if (!System.IO.Directory.Exists(this.LogPath))
                System.IO.Directory.CreateDirectory(this.LogPath);

            System.IO.File.AppendAllText(this.LogPath + "\\log_" + DateTime.Now.ToShortDateString() + "_E"
                , DateTime.Now.ToLongTimeString() + " : " + _s + "\n");
        }

        public void ILog(string _s)
        {
            if (!System.IO.Directory.Exists(this.LogPath))
                System.IO.Directory.CreateDirectory(this.LogPath);

            System.IO.File.AppendAllText(this.LogPath + "\\log_" + DateTime.Now.ToShortDateString() + "_I"
                , DateTime.Now.ToLongTimeString() + " : " + _s + "\n");
        }
    }
}
